app.controller("brandController",function($scope,$controller,brandService){
	
	$controller('baseController',{$scope:$scope});//继承
			
	//分页显示
	$scope.findPage = function(page,size){
		
		brandService.findPage(page,size).success(
			function(response){
				$scope.list = response.rows;
				$scope.paginationConf.totalItems=response.total;//更新总记录数
		});
	};
	
	//修改信息回显
	$scope.findOne = function(id){
		
		brandService.findOne(id).success(
			function(response){
				$scope.entity = response;
			}
		)
	}
	
	//添加或修改
	$scope.save = function(){
		
		var methodName = 'add';
		if($scope.entity.id != null){
			methodName = 'update';
		}
		
		brandService.save($scope.entity).success(
			function(response){
				if(response.success){
					$scope.reloadList();
				}else{
					alert(response.message);
				}
			}
		);
	};
	
	//删除所选
	$scope.del = function(){
		var ids = $("[name='ids']").serialize()
		brandService.del(ids).success(
			function(response){
				if(response.success){
					$scope.reloadList();
				}else{
					alert(response.message);
				}
			}
		)
	
	}
	
	//条件查询
	$scope.searchEntity = {};
	$scope.search = function(page,size){
		
		brandService.search(page,size,$scope.searchEntity).success(
			function(response){
				$scope.list = response.rows;
				$scope.paginationConf.totalItems=response.total;//更新总记录数
		});
	};
	
});